package top.wkl.springboot3.aop;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import top.wkl.springboot3.exception.AppException;
import top.wkl.springboot3.service.AuthService;

@Component
@Slf4j
@RequiredArgsConstructor
@Order(40)
@Aspect
public class AuthAop implements BaseAop {
    private final AuthService authService;
    public static final Integer AUTH_ERROR = 1000;
    public static final String AUTH_MESSAGE = "需要相关角色登录！";

    @Before("controller()")
    public void before(JoinPoint jp) {
        if (!authService.auth()) {
            throw AppException.getInstance(AUTH_ERROR, AUTH_MESSAGE);
        }
    }


}
